//
//  ViewController.m
//  2.18homework
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end
// 纯代码
@implementation ViewController
-(void) addbuttonWithTitle:(NSString *)title andTag:(int)tag andColor:(UIColor *)color andFrame:(CGRect)frame
{
    UIButton *btn=[[UIButton alloc]initWithFrame:frame];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font=[UIFont systemFontOfSize:15];
    btn.tag=tag;
    [btn addTarget:self action:@selector(BtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.lable=[[UILabel alloc]initWithFrame:CGRectMake(40, 40, 200, 50)];
    self.lable.text=@"label";
    self.lable.textColor=[UIColor redColor];
    [self.view addSubview:self.lable];
    [self addbuttonWithTitle:@"简单提示框" andTag:1 andColor:[UIColor redColor] andFrame:CGRectMake(15, 150, 100, 50)];
    [self addbuttonWithTitle:@"多按钮" andTag:2 andColor:[UIColor greenColor] andFrame:CGRectMake(115, 150, 100, 50)];
    [self addbuttonWithTitle:@"带输入框" andTag:3 andColor:[UIColor blueColor] andFrame:CGRectMake(215, 150, 100, 50)];
    [self addbuttonWithTitle:@"操作符" andTag:4 andColor:[UIColor blueColor] andFrame:CGRectMake(315, 150, 100, 50)];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)BtnPressed:(UIButton *)sender
{
    if (sender.tag == 1)
    {
        
    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"窗口1" message:@"你是天才吗？" delegate:self cancelButtonTitle:@"董死魔犬是" otherButtonTitles:@"白然巨屎是", nil];
    [alertView show];
    }


    else if (sender.tag == 2)
{

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"窗口2" message:@"中午吃什么" delegate:self cancelButtonTitle:@"肉" otherButtonTitles:@"屎",@"不吃",nil];
    [alertView show];
}



    else if (sender.tag == 3)
    {

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"窗口3" message:@"请输入用户名 密码！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [alertView show];
}

else
{
    UIActionSheet *sheet =[[UIActionSheet alloc] initWithTitle:@"窗口4" delegate:self cancelButtonTitle:@"你去吧 我吃过了" destructiveButtonTitle:@"好的 一起去吃KFC" otherButtonTitles:@"好的 一起去吃大保健", nil];
    [sheet showInView:self.view];

}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"用户点了第几个按钮 %i , 用户点的按钮信息 %@",buttonIndex+1,[alertView buttonTitleAtIndex:buttonIndex]);
    
    if ([alertView.title isEqualToString:@"窗口3"]) {
        NSString *info = [NSString stringWithFormat:@"用户名:%@，密码:%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text];
        self.lable.text = info;
        
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"用户选择第几个按钮 %i，用户选择的按钮信息 %@",buttonIndex +1,[actionSheet buttonTitleAtIndex:buttonIndex]);
    NSLog(@"操作表的标题%@",actionSheet.title);
    if (buttonIndex == actionSheet.destructiveButtonIndex) {
        NSLog(@"用户选择了destructiveBtn");
    }
    else if (buttonIndex == actionSheet.cancelButtonIndex)
    {
        NSLog(@"用户选择了cancelBtn");
    }
    
}

@end
